﻿/****************************************************************
  Author:  Ievgenii Nazaruk, ievgenii.nazaruk@gmail.com 
 License:  Microsoft Public License (Ms-PL)
          ( http://www.opensource.org/licenses/ms-pl.html or
            http://www.microsoft.com/opensource/licenses.mspx )
*****************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TableParsers
{
    public enum ClassType 
    {
        Group,
        Club,
        Business,
        Grammar,
        Writing,
        Reading,
        Conversation,
        FirstClass,
        ProgressFollowup,
        Unknown
    }

    public enum ClassKind
    {
        Group,
        Club,
        Bussiness,
        Workshop,
        Management,
        Unknown
    }

    [Serializable]
    public class ClassName: IEquatable<ClassName>, IComparable<ClassName>, IComparable
    {
        private String m_fullName = null;
        public String FullName
        {
            get
            {
                return m_fullName;
            }
        }

        private String m_name = null;
        public String Name
        {
            get
            {
                return m_name;
            }
        }

        private ClassType m_type = ClassType.Unknown;
        public ClassType Type
        {
            get
            {
                return m_type;
            }

            private set
            {
                m_type = value;
            }
        }

        public ClassKind Kind
        {
            get
            {
                if (Type == ClassType.Group)
                {
                    return ClassKind.Group;
                }
                else if (Type == ClassType.Club)
                {
                    return ClassKind.Club;
                }
                else if (Type == ClassType.Business)
                {
                    return ClassKind.Bussiness;
                }
                else if (Type == ClassType.Grammar ||
                         Type == ClassType.Reading ||
                         Type == ClassType.Writing ||
                         Type == ClassType.Conversation)
                {
                    return ClassKind.Workshop;
                }
                else if (Type == ClassType.ProgressFollowup ||
                         Type == ClassType.FirstClass)
                {
                    return ClassKind.Management;
                }
                else
                {
                    return ClassKind.Unknown;
                }
            }
        }

        public ClassName(String fullName, String name, ClassType type)
        {
            Type = type;
            m_fullName = fullName;
            m_name = name;            
        }       

        public override string ToString()
        {
            switch (Kind)
            {
                case ClassKind.Club:
                    {
                        return "Club - " + Name;
                    }
                case ClassKind.Group:
                    {
                        return "Group Class (" + Name + ") ";
                    }
                case ClassKind.Workshop:
                    {
                        return Name + " Workshop";
                    }
                case ClassKind.Management:
                    {
                        return Name;
                    }
                case ClassKind.Bussiness:
                    {
                        return Name;
                    }
            }

            return FullName;
        }
        public override int GetHashCode()
        {
            int hashCode = 0;

            unchecked
            {
                hashCode += 373 * Name.GetHashCode();
                hashCode += 373 * Type.GetHashCode();
            }

            return hashCode;
        }

        public override bool Equals(object obj)
        {
            if (Object.ReferenceEquals(null, obj))
            {
                return false;
            }

            if (Object.ReferenceEquals(this, obj))
            {
                return true;
            }

            ClassName other = obj as ClassName;
            if (!Object.ReferenceEquals(null, other))
            {
                return Equals(other);
            }

            return false;
        }
        public bool Equals(ClassName other)
        {
            if (Object.ReferenceEquals(null, other))
            {
                return false;
            }

            if (Object.ReferenceEquals(this, other))
            {
                return true;
            }

            return Name == other.Name &&
                   Type == other.Type;
        }

        public int CompareTo(Object other)
        {
            return CompareTo((ClassName)other);
        }
        public int CompareTo(ClassName other)
        {
            if (Name != other.Name)
            {
                return Name.CompareTo(other.Name);
            }

            return Type.CompareTo(other.Type);
        }

        public static bool operator ==(ClassName left, ClassName right)
        {
            if (Object.ReferenceEquals(left, right))
            {
                return true;
            }

            if (Object.ReferenceEquals(left, null) || 
                Object.ReferenceEquals(right,null))
            {
                return false;
            }

            return left.Equals(right);
        }
        public static bool operator !=(ClassName left, ClassName right)
        {
            return !(left == right);
        }
        public static bool operator <(ClassName left, ClassName right)
        {
            return left.CompareTo(right) < 0;
        }
        public static bool operator <=(ClassName left, ClassName right)
        {
            return left.CompareTo(right) <= 0;
        }
        public static bool operator >(ClassName left, ClassName right)
        {
            return left.CompareTo(right) > 0;
        }
        public static bool operator >=(ClassName left, ClassName right)
        {
            return left.CompareTo(right) >= 0;
        }
        
    }
}
